package showBooks.service;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class ShowBooks {
    Connection connection = ConnectionTest.getConnection();
    Statement statement = null;
    ResultSet resultSet = null;
    List<Information> BooksList = new ArrayList<>();
    Information information = null;

    String sql = "SELECT * FROM books ";
    public ShowBooks(){

    }

    public void viewList() throws SQLException {
        //连接数据库
        try {
            statement = connection.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            resultSet = statement.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //遍历查询结果
        while (resultSet.next()) {
            //查询数据库，将信息录入list集合

            information = new Information();
            information.setId(resultSet.getInt("id"));
            information.setBookName(resultSet.getString("bookName"));
            information.setAuthor(resultSet.getString("author"));
            information.setKind(resultSet.getString("kind"));
            information.setSrc(resultSet.getString("src"));
            information.setCurrent_number(resultSet.getString("current_number"));
            information.setAll_number(resultSet.getString("all_number"));
            information.setPosition(resultSet.getString("position"));
            BooksList.add(information);


            resultSet.close();
            statement.close();
            connection.close();




        }


    }}